export const baseUrl = 'http://hmscyfkdu.cn.utools.club'
import { getToken } from './auth.js'

const request = (url, method = "GET", data={} ,) => {
	
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title:'加载中',
		})
		uni.request({
			url: baseUrl + url,
			header:{
				Authorization: getToken()
			},
			method,
			data,
			timeout: 5000,
			success: (res) => {
				uni.hideLoading()
				const {data} = res
				if(data.code === 200){
					resolve(data)
				}else {
					return uni.showToast({
						icon:'none',
						title:data.message
					})
				}
			},
			fail: (err) => {
				uni.hideLoading()
				uni.showToast({
					icon:'none',
					title:err.errMsg
				})
				reject(err)
			}
		})
	})
}

export default request
